Let's Encrypt





無料SSL証明書を発行してくれる認証局があることを知りました Let's Encrypt と言うそうです。

ありがたいことです。

[-] 1. wtech.jp 証明書

  1. 下記をインストール:
    $ sudo apt-get install certbot
    $ sudo apt-get install python3-certbot-apache
  2. 実行:
    1. wtech.jp
      $ sudo systemctl stop apache2
      $ sudo certbot --authenticator standalone --installer apache -w /var/www/html         -d wtech.jp
      Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      1: No redirect - Make no further changes to the webserver configuration.
      2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
      new sites, or if you're confident your site works on HTTPS. You can undo this
      change by editing your web server's configuration.
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

下記ファイルが生成されてます:

/etc/letsencrypt/live/wtech.jp/
  cert.pem      -> ../../archive/wtech.jp/certN.pem
  chain.pem     -> ../../archive/wtech.jp/chainN.pem
  fullchain.pem -> ../../archive/wtech.jp/fullchainN.pem
  privkey.pem   -> ../../archive/wtech.jp/privkeyN.pem

ここで N は初回 1, 以降更新ごとに 2, 3, ... となるようです。

90日で期限が一旦切れるので、その時にでも更新手順をチェックしておきます。

[-] 2. ワイルドカード証明書

(2019/04/21) ワイルドカード証明書は90日後の更新時、 自動で更新してくれないようです。

各自で DNS にアクセスする更新スクリプトを用意しないといけないようで。

AWS route53 等は自動更新用のスクリプトがあるようですが、 私が使用している ホニャララ.com はざっと見た範囲ではありませんでした。

ワイルドカードは止めてその都度登録することにしようと思います。 どうせ数少ないし。

ということで、以下は単なるメモとして↓

---

*.wtech.jp があれば wtech.jp の証明書は要らないと思っていたのですが、 違ってました。 *.wtech.jp はあくまで wtech.jp のサブドメインのみのようなので、 wtech.jp 用は別途必要でした。

  1. インストール
    $ sudo add-apt-repository ppa:certbot/certbot
    $ sudo apt update
    $ sudo apt install certbot
  2. 証明書の取得
    $ sudo certbot certonly --manual -d *.wtech.jp --agree-tos --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
  3. TXTレコードの設定 上の certbotコマンド実行中、 _acme-challenge.wtech.jp の TXT レコードに 指定したキーを埋めろと出てくる:
    Please deploy a DNS TXT record under the name
    _acme-challenge.wtech.jp with the following value:
    ************************************** (実際はキー)
    (2019/01/26) wtech.jp 用の _acme-challenge.wtech.jp TXTレコードとは別に *.wtech.jp 用の _acme-challenge.wtech.jp TXTレコードの計2つ要るようです。 これを誤解していて wtech.jp 用のキーに上書きしていたため renew 時に エラーになってしまいましたorz 最初からやり直しました。
  4. 契約先 DNS に設定し伝搬(*)されるまで待つ。 確認は例えば:
    $ nslookup -q=txt _acme-challenge.wtech.jp
    ...
    Non-authoritative answer:
    _acme-challenge.wtech.jp        text ="**************************************"
    (*)おそらく、証明書を発行しようとする Let's Encrypt が 「正しく DNS 上に登録されているか」を確認するのだと思う。
  5. [Enter]キーを押す。 Congratulations! と出れば成功。

To non-interactively renew *all* of your certificates, run "certbot renew"

とのこと。

[-] 2.1. 参考

[-] 3. 更新

90日の期限切れの件。certbot.timer なる systemctl が自動的にやってくれていると思っていましたが、 ずっと止まっていたようで、certbot から「後何日で切れるよ」と言う通知が来ました。

で、期限切れ当日、手で renew すると

$ sudo certbot renew
...
Attempting to renew cert (wtech.jp) from /etc/letsencrypt/renewal/wtech.jp.conf
produced an unexpected error: Problem binding to port 80: Could not bind to IPv4
or IPv6.. Skipping.

とエラー。ググると、取り敢えず SSL(port 443) apache を止めると行けるとのことで、 取り敢えず今回はそれで切り抜けました(2019/03/03 時点)。

[-] 3.1. 時々 apache2 が止まる件

  • タイミング的に certbot renew が引き金。
  • /etc/letsencrypt/renewal-hooks/ の pre, post は毎回実行されるとのこと。 deploy は renew 時のみ、と。

/var/log/syslog と /var/log/apache2/error.log を watch してみる。

[-] 4. 削除

$ sudo certbot revoke --cert-path /etc/letsencrypt/live/wtech.jp-0001/cert.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you like to delete the cert(s) you just revoked, along with all earlier
and later versions of the cert?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es (recommended)/(N)o: y

※ ググると、 revoke 後に delete しないといけない、と言う記事がヒットしますが、 今は revoke コマンドで削除までやってくれるようです:






Generated by juli 2.3.2